<template>
    <div class="profile-container">
        <div class="user-profile">
            <div class="info">
                <template v-if="isLogin">
                  <img class="user-img" :src="userInfo.photo" alt="">
                  <h3 class="info-name">{{ userInfo.name }}</h3>
                  <span class="setting" @click="$router.push({path:'/setting'})">个人设置</span>
                <van-icon size="16" name="arrow" />
                </template>
                <template v-else>
                  <span>未登录</span>
                  <div class="nologin-info">
                    <span class="nologin-setting" @click="$router.push({path:'/login'})">去登录</span>
                    <van-icon size="16" name="arrow" />
                  </div>
                </template>
            </div>
            <van-row>
                <van-col span="6" @click="$router.push({ path: '/myDynamic' })">
                    <p>{{ userInfo.art_count }}</p>
                    <p>动态</p>
                </van-col>
                <van-col span="6" @click="$router.push({ path:'/myFans'})">
                    <p>{{ userInfo.follow_count }}</p>
                    <p>关注</p>
                </van-col>
                <van-col span="6">
                    <p>{{ userInfo.fans_count }}</p>
                    <p>粉丝</p>
                </van-col>
                <van-col span="6">
                    <p>{{ userInfo.like_count }}</p>
                    <p>被赞</p>
                </van-col>
            </van-row>

            <van-row class="user-links">
                <van-col span="6">
                    <div class="links-icon" @touchstart="$router.push({name:'notice'})">
                        <van-icon size="25" name="volume" />
                    </div>
                    <p>消息通知</p>
                </van-col>
                <van-col span="6">
                    <div class="links-icon" @touchstart="$router.push({name:'myCollection'})">
                        <i class="toutiao toutiao-shoucang"></i>
                    </div>
                    <p>我的收藏</p>
                </van-col>
                <van-col span="6">
                   <div class="links-icon" @touchstart="$router.push({name:'readHistory'})">
                        <i class="toutiao toutiao-lishi"></i>
                    </div>
                    <p>阅读历史</p>
                </van-col>
                <van-col span="6">
                  <div class="links-icon">
                        <i class="toutiao toutiao-zuopin"></i>
                    </div>
                    <p>我的作品</p>
                    
                </van-col>
            </van-row>
            <!-- 更多服务 -->
             <van-row class="user-links more-serve">
               <h3>更多服务</h3>
                <van-col span="6" @click="$router.push({path:'/userChart'})">
                    <div class="links-icon">
                        <van-icon size="25" name="service-o" />
                    </div>
                    <p>小智同学</p>
                </van-col>
                <van-col span="6">
                    <div class="links-icon">
                        <van-icon size="25" name="question-o" />
                    </div>
                    <p>用户反馈</p>
                </van-col>
            </van-row>
        </div>
    </div>
</template>
<script>
import { getUserInfo } from '@/api/user'
import { mapState } from 'vuex'
import { getItem } from '@/utils/storage'
export default {
    name: 'ToutiaoMIndex',
    data() {
        return {
            isLogin: false,
            userInfo: {},
        };
    },
    mounted() {
      // console.log(this.tokenInfo && getItem('user-token'));
      if (this.tokenInfo.token) {
        this.getUserInfoData()
      }
    },
    computed: {
      ...mapState('user',['tokenInfo'])
    },
    methods: {
      async getUserInfoData() {
          const { data } = await getUserInfo()
          this.userInfo = data.data
          this.isLogin = true
      }
    },
};
</script>

<style lang="less" scoped>
.profile-container{
  background-color: #f8f8f8;
  height: 100%;
  .user-profile{
    // width: 100%;
    height: 231px;
    padding: 0 20px;
    display: block;
    background: linear-gradient(318deg,#b2b5db,#565482 70%,#494675);
    color: #fff;
    border-bottom-left-radius: 10.66667rem 1.6rem;
    border-bottom-right-radius: 10.66667rem 1.6rem;
    margin-bottom: 1.28rem;
    .info{
      display: flex;
      padding: 20px 0;
      height: 3.46667rem;
      align-items: center;
      justify-content: space-around;
      .user-img{
        width: 1.33333rem;
        height: 1.33333rem;
        border: .08rem solid #7674a2;
        border-radius: 50%;
      }
      .info-name {
        font-size: .53333rem;
        font-weight: 400;
        margin-left: .26667rem;
        flex: 1;
      }
      .setting{
        color: #fff;
        line-height: 1;
        font-size: .32rem;
      }
      .nologin-info{
        height: 60px;
        color: #fff;
        line-height: 60px;
        font-size: .32rem;
        display: flex;
        align-items: center;
        position: absolute;
        right: 20px;
      }
    }
    p{
      margin: 0;
      text-align: center;
      height: .53333rem;
      font-size: 14px;
    }
    .user-links{
      padding: .4rem 0;
      font-size: .32rem;
      text-align: center;
      background-color: #fff;
      border-radius: .26667rem;
      color: #333;
      position: relative;
      top: .53333rem;
      h3{
        padding-left:.53333rem ;
        text-align: left;
      }
      .links-icon{
        margin-bottom: 5px;
        i{
          font-size: 25px;
        }
      }
      p{
        font-size: 12px;
        margin-top: 5px;
      }
    }
    /deep/.more-serve{
      margin-top: 20px;
    }
  }
}

</style>